package org.itboys.core.service.mongo.web;

import org.itboys.core.common.SundayCommonConstants;
import org.itboys.core.entity.mongo.dispatch.SundayDispatchModel;
import org.itboys.mongodb.core.MongoDataSource;
import org.itboys.mongodb.service.BaseMongoService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Author：贾琦磊
 * @Date：2018/12/18
 * @Description：调度单的模板信息
 */
@Service
public class SundayDispatchModelService extends BaseMongoService<SundayDispatchModel>{
    @Resource(name = "mobileDs")
    private MongoDataSource sundayDataSource;
    @Override
    protected MongoDataSource getMongoDataSource() {
        return sundayDataSource;
    }

    @Override
    protected Class<SundayDispatchModel> getEntityClass() {
        return SundayDispatchModel.class;
    }

    public void save(Long orderId,List<SundayDispatchModel> models){
        Map<String,Object> param=new HashMap<>();
        param.put("isDeleted", SundayCommonConstants.NO);
        param.put("orderId",orderId);
        super.delete(param);
        for (SundayDispatchModel dm:models
             ) {
            dm.setOrderId(orderId);
        }
        super.batchSave(models);
    }
}
